package com.company.card_service.vo;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel(value = "全局统一返回结果")
public class Result<T> {

    @ApiModelProperty(value = "返回码")
    private Integer code;

    @ApiModelProperty(value = "返回消息")
    private String message;

    @ApiModelProperty(value = "返回数据")
    private T data;

    public Result(){

    }
    public static<T> Result<T> success(Integer code,String msg){
        Result<T> result=new Result<>();
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }
    public static<T> Result<T> success(Integer code,String msg,T data){
        Result<T> result=new Result<>();
        if(data == null) return result;
        result.setCode(code);
        result.setMessage(msg);
        result.setData(data);
        return result;
    }
    public static<T> Result<T> success(T data){
        Result<T> result=new Result<>();
        if(data == null) return result;
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }
    public static<T> Result<T> fail(Integer code,String msg){
        Result<T> result=new Result<>();
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }
}
